﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DamageCalculator.SubForms
{
    public partial class AddCharacterDialog : Form
    {
        Classes.Character RetChar;
        List<Classes.Character> aChar;
        String RetCharString;
        bool returnsChar;

        public AddCharacterDialog(List<Classes.Character> availableChars)
        {
            InitializeComponent();
            foreach (Classes.Character C in availableChars)
            {
                this.comboBox1.Items.Add(C.Name);
            }
            this.aChar = availableChars;
        }

        public Classes.Character SelectedCharacter
        {
            get { return this.RetChar; }
        }

        public bool ReturnsCharacter
        {
            get { return this.returnsChar; }
        }

        public String SelectedCharacterString
        {
            get { return this.RetCharString; }
        }

        private void Btn_Submit_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.RetChar = this.aChar.Find(
                delegate(Classes.Character C)
                {
                    return C.Name == this.comboBox1.Text;
                }
            );

            if (this.RetChar != null)
                this.returnsChar = true;
            else
            {
                this.RetCharString = this.comboBox1.Text;
                this.returnsChar = false;
            }
            this.Close();
        }

        private void Btn_Cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void AddCharacterDialog_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.Btn_Submit_Click(null, null);
            }
        }
    }
}
